#!/bin/bash
# git_quick_push.sh
set -e

# current_branch=$(git branch --show-current)

mapfile -t remotes < <(git remote)
if [ ${#remotes[@]} -eq 0 ]; then
    echo "❌ 没有找到任何 remote!"
    exit 1
elif [ ${#remotes[@]} -eq 1 ]; then
    remote=${remotes[0]}
    echo "使用 remote: $remote"
else
    echo "可选的 remote:"
    select r in "${remotes[@]}"; do
        [[ -n $r ]] && { remote=$r; break; }
    done
fi

mapfile -t branches < <(git branch -a | sed 's/^[* ]*//;s|remotes/||g' | sort -u)
echo "可选分支："
select b in "${branches[@]}"; do
    [[ -n $b ]] && { branch_name=$b; break; }
done

read -rp "请输入 commit 信息: " commit_msg

echo 
git add .
git commit -m "$commit_msg"
git push $remote HEAD:master

echo "✅ 已推送至 $remote/master"